package com.lowca.news.web.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;

/**
 * 系统初始化监听器，这个监听器拥有最高优先级，它启动的时候，spring环境尚未准备就绪，因此不能在这里访问spring上下文
 * 
 * @author konglz
 * 
 */
public class StartupListener implements ServletContextListener {

	private static Log log = null;

	@Override
	public void contextInitialized(ServletContextEvent sce) {
		ServletContext application = sce.getServletContext();
		String path = application.getRealPath("/");
		System.setProperty("WebRoot", path);
		PropertyConfigurator.configure(path
				+ "/WEB-INF/classes/log4j.properties");
		System.out.println("初始化日志配置");
		log = LogFactory.getLog(StartupListener.class);
		log.info("**************************系统启动**************************");
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		log.info("**************************系统停止**************************");
	}

}
